package com.note.chh.notebook.Uitls;

import android.content.Context;
import android.content.DialogInterface;

import com.qmuiteam.qmui.widget.dialog.QMUIDialog;
import com.qmuiteam.qmui.widget.dialog.QMUIDialogAction;

/**
 * Created by caihuahui on 2018/1/9.
 */

public class DialogUtils {

    //取消没有其它操作，返回对象以添加确定按钮用于处理确定事件
    public static QMUIDialog.MessageDialogBuilder sureDialog(Context context,String title,String message){
       final QMUIDialog.MessageDialogBuilder dialogMessage  = new QMUIDialog.MessageDialogBuilder(context)
                .setTitle(title)
                .setMessage(message)
                .addAction("取消", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                    }
                });
        return dialogMessage;
    }
    //返回对象以添加取消和确定按钮并处理事件
    public static QMUIDialog.MessageDialogBuilder cancelSureDialog(Context context,String title,String message){
       final QMUIDialog.MessageDialogBuilder dialogMessage  = new QMUIDialog.MessageDialogBuilder(context)
                .setTitle(title)
                .setMessage(message)
                ;
        return dialogMessage;
    }

    /**
     * 菜单类型对话框
     private void showMenuDialog() {
         final String[] items = new String[]{"选项1", "选项2", "选项3"};
         new QMUIDialog.MenuDialogBuilder(getActivity())
         .addItems(items, new DialogInterface.OnClickListener() {
        @Override
        public void onClick(DialogInterface dialog, int which) {
            Toast.makeText(getActivity(), "你选择了 " + items[which], Toast.LENGTH_SHORT).show();
            dialog.dismiss();
            }
        })
         .show();
     }
     */

    //弹出单选菜单类型对话框
    public static QMUIDialog.MenuDialogBuilder menuDialog(Context context){
       final QMUIDialog.MenuDialogBuilder menuDialog = new QMUIDialog.MenuDialogBuilder(context);
        /*.addItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {
                        Toast.makeText(getActivity(), "你选择了 " + items[which], Toast.LENGTH_SHORT).show();
                        dialog.dismiss();
                    }
                })*/
        return menuDialog;
    }

    //多选菜单类对话框
    public static QMUIDialog.MultiCheckableDialogBuilder multiChoiceDialog(Context context,CharSequence[] items){
//        final String[] items = new String[]{"选项1", "选项2", "选项3", "选项4", "选项5", "选项6"};
        final QMUIDialog.MultiCheckableDialogBuilder builder = new QMUIDialog.MultiCheckableDialogBuilder(context)
//                .setCheckedItems(new int[]{1, 3})
                .addItems(items, new DialogInterface.OnClickListener() {
                    @Override
                    public void onClick(DialogInterface dialog, int which) {

                    }
                });
        builder.addAction("取消", new QMUIDialogAction.ActionListener() {
            @Override
            public void onClick(QMUIDialog dialog, int index) {
                dialog.dismiss();
            }
        });
        /*builder.addAction("提交", new QMUIDialogAction.ActionListener() {
            @Override
            public void onClick(QMUIDialog dialog, int index) {
                String result = "你选择了 ";
                for (int i = 0; i < builder.getCheckedItemIndexes().length; i++) {
                    result += "" + builder.getCheckedItemIndexes()[i] + "; ";
                }
                Toast.makeText(getActivity(), result, Toast.LENGTH_SHORT).show();
                dialog.dismiss();
            }
        });*/
//        builder.show();
        return builder;
    }


    //带输入框的dialog
    public static QMUIDialog.EditTextDialogBuilder editTextDialog(Context context,String title,String hint,int inputType){
        final QMUIDialog.EditTextDialogBuilder builder = new QMUIDialog.EditTextDialogBuilder(context);
        builder.setTitle(title)
                .setPlaceholder(hint)
                .setInputType(inputType)//InputType.TYPE_CLASS_TEXT
                .addAction("取消", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        dialog.dismiss();
                    }
                })
                /*.addAction("确定", new QMUIDialogAction.ActionListener() {
                    @Override
                    public void onClick(QMUIDialog dialog, int index) {
                        CharSequence text = builder.getEditText().getText();
                        if (text != null && text.length() > 0) {
                            Toast.makeText(getActivity(), "您的昵称: " + text, Toast.LENGTH_SHORT).show();
                            dialog.dismiss();
                        } else {
                            Toast.makeText(getActivity(), "请填入昵称", Toast.LENGTH_SHORT).show();
                        }
                    }
                })
                .show()*/;
        return builder;

    }


}
